﻿Public Class Fund

#Region "Properties"

    Private _FundName As String
    Public Property FundName() As String
        Get
            Return _FundName
        End Get
        Set(ByVal value As String)
            _FundName = value
        End Set
    End Property

    Private _ID As Integer
    Public Property ID() As Integer
        Get
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property

#Region "Fund Mapping"

    Private _IsNoneMapped As Boolean
    Public Property IsNoneMapped() As Boolean
        Get
            Return _IsNoneMapped
        End Get
        Set(ByVal value As Boolean)
            _IsNoneMapped = value
        End Set
    End Property

    Private _IsGlobalNameMap As Boolean
    Public Property IsGlobalNameMap() As Boolean
        Get
            Return _IsGlobalNameMap
        End Get
        Set(ByVal value As Boolean)
            _IsGlobalNameMap = value
        End Set
    End Property

    Private _MappedToName As String
    Public Property MappedToName() As String
        Get
            Return _MappedToName
        End Get
        Set(ByVal value As String)
            _MappedToName = value
        End Set
    End Property

    Private _RenameCCYAndBroker As dsFund.FundRenameDataTable
    Public Property RenameCCYAndBroker() As dsFund.FundRenameDataTable
        Get
            Return _RenameCCYAndBroker
        End Get
        Set(ByVal value As dsFund.FundRenameDataTable)
            _RenameCCYAndBroker = value
        End Set
    End Property

    Private _MappingBrokers As dsFund.FundBrokerMapDataTable
    Public Property MappingBroker() As dsFund.FundBrokerMapDataTable
        Get
            Return _MappingBrokers
        End Get
        Set(ByVal value As dsFund.FundBrokerMapDataTable)
            _MappingBrokers = value
        End Set
    End Property


#End Region

#End Region

    Sub New(ByVal Fund As String)
        Me.FundName = Fund
        Me.RenameCCYAndBroker = New dsFund.FundRenameDataTable
        Me.MappingBroker = New dsFund.FundBrokerMapDataTable
        Me.IsNoneMapped = False
        Me.IsGlobalNameMap = False
    End Sub
    Sub New()

    End Sub

    Public Overrides Function ToString() As String
        Return Me.FundName
    End Function

    Sub Rename(ByVal CCY1 As String, ByVal CCY2 As String, ByVal Broker As String)
        If IsGlobalNameMap = True Then
            Me.FundName = Me.MappedToName
        Else
            For Each drRename As dsFund.FundRenameRow In Me.RenameCCYAndBroker
                If drRename.Broker.ToLower = "all" Then

                    If drRename.CCY.ToLower = "none" Then
                        Me.FundName = drRename.NewName
                    ElseIf (CCY1 = drRename.CCY OrElse CCY2 = drRename.CCY) Then
                        Me.FundName = drRename.NewName
                    End If

                ElseIf drRename.Broker = Broker Then

                    If drRename.CCY.ToLower = "none" Then
                        Me.FundName = drRename.NewName
                    ElseIf (CCY1 = drRename.CCY OrElse CCY2 = drRename.CCY) Then
                        Me.FundName = drRename.NewName
                    End If

                End If

            Next
        End If
    End Sub

    Function MapBroker(ByVal CCY1 As String, ByVal CCY2 As String, ByVal Broker As String) As Broker

        For Each drMap As dsFund.FundBrokerMapRow In Me.MappingBroker
            If drMap.ToBroker = "no upload" Then
                Return Nothing
            Else
                If drMap.CCY.ToLower = "none" Then
                    If drMap.FromBroker = Broker Then
                        Return My.Settings.AllBrokers.GetBrokerByName(drMap.ToBroker)
                    End If
                Else
                    If (drMap.CCY = CCY1 OrElse drMap.CCY = CCY2) AndAlso _
                    drMap.FromBroker = Broker Then
                        Return My.Settings.AllBrokers.GetBrokerByName(drMap.ToBroker)
                    End If
                End If
            End If
        Next
        Return My.Settings.AllBrokers.GetBrokerByName(Broker)
    End Function

    Sub RemoveSpecialChars()
        'Dim sProhibited As String() = {"~", "_", "!", "@", "#", "$", "%", "^", "&", "<", "*", "(", ")", "+", "=", "{", "}", "[", "]", "\", ";", "'", "?", "/", """", ""}
        Dim sProhibited As String = "~,_,!,@,#,$,%,^,&<*,(,),+,=,{,},[,],\,;,',?,/" & "," & """"
        If My.Settings.sBIC.ToLower.Trim = "genmotamxxx" Then sProhibited = sProhibited & ",P4,P5,P6,P7,P8,P10" 'ONLY FOR PROMARK 
        For Each sChar As String In sProhibited.split(",")
            Me.FundName = Me.FundName.Replace(sChar, String.Empty)
        Next
    End Sub
End Class
